//schooling and other instruments
clear
clear matrix
clear mata
cap log close
************************************************************************************
* DIRECTORY ROADMAP
sysdir set PLUS C:\ado\plus\c

global dir1 C:\Users\hab55\Dropbox\Second_paper_Ghana\2023_EDCC_Price\Data
global dir2 C:\Users\hab55\Dropbox\Second_paper_Ghana\2023_EDCC_Price\Do
global dir3 C:\Users\hab55\Dropbox\Second_paper_Ghana\2023_EDCC_Price\Output


clear
///////////////////////////////////////////////////////////////////////
use "$dir1\schooling_other_instruments_data", clear

***Table D.1:

***attendance

///Panel A: second stage event IVs

ivreg2  attendance  (Y0=Z0_d  Z0_f Z0_w Z0_e ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year [aw=weight] if agey>=6 & agey<=17,   cluster (ROB) 
boottest Y0=0 ,    nograph  
gen smpl_1=0
replace smpl_1=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  attendance  (Y0=Z0_d  Z0_f Z0_w Z0_e ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year [aw=weight] if agey>=6 & agey<=11,  cluster (ROB)  
boottest Y0=0 ,    nograph   
gen smpl_2=0
replace smpl_2=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  attendance  (Y0=Z0_d  Z0_f Z0_w Z0_e ) i.agey gender genderhd i.ROB#c.year  i.ROB i.YOB i.year  [aw=weight] if agey>=12 & agey<=14,   cluster (ROB)  
boottest Y0=0 ,     nograph  
gen smpl_3=0
replace smpl_3=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  attendance  (Y0=Z0_d  Z0_f Z0_w Z0_e ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year [aw=weight] if agey>=15 & agey<=17,   cluster (ROB)  
boottest Y0=0 ,   nograph  
gen smpl_4=0
replace smpl_4=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//////////Panel A: second stage weather IVs

ivreg2  attendance  (Y0=Z0_r_ano  Z0_t_ano ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB  i.year  [aw=weight] if agey>=6 & agey<=17,   cluster (ROB)  
boottest Y0=0 ,     nograph  
gen smpl_5=0
replace smpl_5=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  attendance  (Y0=Z0_r_ano  Z0_t_ano ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB  i.year  [aw=weight] if agey>=6 & agey<=11,   cluster (ROB)  
boottest Y0=0 ,    nograph  
gen smpl_6=0
replace smpl_6=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  attendance  (Y0=Z0_r_ano  Z0_t_ano ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB  i.year  [aw=weight] if agey>=12 & agey<=14,   cluster (ROB)  
boottest Y0=0 ,    nograph  
gen smpl_7=0
replace smpl_7=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  attendance  (Y0=Z0_r_ano  Z0_t_ano ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB  i.year  [aw=weight] if agey>=15 & agey<=17,   cluster (ROB)  
boottest Y0=0 ,     nograph  
gen smpl_8=0
replace smpl_8=1 if e(sample)==1
//outreg2 using "$dir3\school_IV_event.tex", keep(Y0 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
/////////////////////////////////////////////////////////////////////////////////

////Panel B: first stage event IVs

areg   Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year i.YOB  i.year [aw=weight] if agey>=6 & agey<=17 & smpl_1==1,  ab(ROB) cluster (ROB) 
//boottest Y0=0 ,    nograph  seed(321448699) 
outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year i.YOB  i.year [aw=weight] if agey>=6 & agey<=11 & smpl_2==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,    nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year i.YOB  i.year  [aw=weight] if agey>=12 & agey<=14 & smpl_3==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year i.YOB  i.year [aw=weight] if agey>=15 & agey<=17 & smpl_4==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
////Panel B: first stage Weather IVs

areg Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB   i.year  [aw=weight] if agey>=6 & agey<=17 & smpl_5==1, ab(ROB)  cluster (ROB)  
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB   i.year  [aw=weight] if agey>=6 & agey<=11 & smpl_6==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,    nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB   i.year  [aw=weight] if agey>=12 & agey<=14 & smpl_7==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,    nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year   i.YOB   i.year  [aw=weight] if agey>=15 & agey<=17 & smpl_8==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\school_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
***grade for age

/////Panel C: Second stage Event IVs
  
ivreg2  ontrack  (Y0_1=Z0_d_1  Z0_f_1 Z0_w_1 Z0_e_1 ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year [aw=weight] if agey>=6 & agey<=17,   cluster (ROB)  
boottest Y0_1=0 ,     nograph  
gen smpl_9=0
replace smpl_9=1 if e(sample)==1

//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  ontrack  (Y0_1=Z0_d_1  Z0_f_1 Z0_w_1 Z0_e_1 ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year [aw=weight] if agey>=6 & agey<=11,   cluster (ROB)  
boottest Y0_1=0 ,     nograph  
gen smpl_10=0
replace smpl_10=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  ontrack  (Y0_1=Z0_d_1  Z0_f_1 Z0_w_1 Z0_e_1 ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year [aw=weight] if agey>=12 & agey<=14,  cluster (ROB)  
boottest Y0_1=0 ,     nograph  
gen smpl_11=0
replace smpl_11=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  ontrack  (Y0_1=Z0_d_1  Z0_f_1 Z0_w_1 Z0_e_1 ) i.agey gender genderhd  i.ROB#c.year  i.ROB i.YOB i.year  [aw=weight] if agey>=15 & agey<=17,   cluster (ROB)  
boottest Y0_1=0 ,     nograph  
gen smpl_12=0
replace smpl_12=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////

////// Panel C: Second stage weather IVs

ivreg2 ontrack  (Y0_1=Z0_r_ano_1  Z0_t_ano_1) i.agey gender genderhd  i.ROB#c.year i.ROB i.YOB i.year  [aw=weight] if agey>=6 & agey<=17,  cluster (ROB)  
boottest Y0_1=0 , nograph   
gen smpl_13=0
replace smpl_13=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  ontrack  (Y0_1=Z0_r_ano_1  Z0_t_ano_1) i.agey gender genderhd  i.ROB#c.year i.ROB i.YOB i.year [aw=weight] if agey>=6 & agey<=11,   cluster (ROB)  
boottest Y0_1=0 ,     nograph  
gen smpl_14=0
replace smpl_14=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  ontrack  (Y0_1=Z0_r_ano_1  Z0_t_ano_1) i.agey gender genderhd  i.ROB#c.year i.ROB i.YOB i.year [aw=weight] if agey>=12 & agey<=14,   cluster (ROB)  
boottest Y0_1=0 ,    nograph  
gen smpl_15=0
replace smpl_15=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

ivreg2  ontrack  (Y0_1=Z0_r_ano_1  Z0_t_ano_1) i.agey gender genderhd  i.ROB#c.year i.ROB i.YOB i.year  [aw=weight] if agey>=15 & agey<=17, cluster (ROB)  
boottest Y0_1=0 ,   nograph  
gen smpl_16=0
replace smpl_16=1 if e(sample)==1
//outreg2 using "$dir3\ontrack_IV_event.tex", keep(Y0_1 ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)


///Panel D: first stage event IVs

areg   Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year  i.YOB i.year [aw=weight] if agey>=6 & agey<=17 & smpl_9==1,  ab(ROB) cluster (ROB) 
//boottest Y0=0 ,    nograph  seed(321448699) 
outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year  i.YOB  i.year [aw=weight] if agey>=6 & agey<=11 & smpl_10==1,  ab(ROB) cluster (ROB) 
//boottest Y0=0 ,    nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year  i.YOB  i.year [aw=weight] if agey>=12 & agey<=14 & smpl_11==1,  ab(ROB) cluster (ROB) 
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg Y0 Z0_d  Z0_f Z0_w Z0_e  i.agey gender genderhd  i.ROB#c.year  i.YOB  i.year [aw=weight] if agey>=15 & agey<=17 & smpl_12==1,  ab(ROB) cluster (ROB)  
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_d  Z0_f Z0_w Z0_e ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////

/// Panel D: first stage weather IVs

areg Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB  i.year  [aw=weight] if agey>=6 & agey<=17 & smpl_13==1, ab(ROB)  cluster (ROB)  
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB  i.year  [aw=weight] if agey>=6 & agey<=11 & smpl_14==1,   ab(ROB)  cluster (ROB)   
//boottest Y0=0 ,    nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB  i.year  [aw=weight] if agey>=12 & agey<=14 & smpl_15==1,   ab(ROB)  cluster (ROB)   
//boottest Y0=0 ,    nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)

areg  Y0 Z0_r_ano  Z0_t_ano  i.agey gender genderhd  i.ROB#c.year  i.YOB i.year  [aw=weight] if agey>=15 & agey<=17 & smpl_16==1,   ab(ROB)  cluster (ROB) 
//boottest Y0=0 ,     nograph  seed(321448699) 

outreg2 using "$dir3\ontrack_1st_stage.tex", keep(Z0_r_ano  Z0_t_ano ) stats(coef se) bdec(3) sdec(3) nocons  label addtext(Region FE, Yes, Survey year FE, Yes, Region time trends, Yes)
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////